package com.tcl.aota.admin.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tcl.aota.admin.dto.Result;
import com.tcl.aota.common.constants.Constants;
import com.tcl.aota.manage.OperLogManager;
import com.tcl.aota.persistent.model.OperLog;

@Controller
public class OperLogController {
    
    @Autowired
    private OperLogManager operLogManager;
    
    @ResponseBody
    @RequestMapping("/operlog/get/{appId}/{pageNo}")
    public Result getByAppId(@PathVariable Integer appId,@PathVariable Integer pageNo) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("start", (pageNo - 1) * Constants.Common.PAGE_SIZE);
        paramMap.put("pageSize", Constants.Common.PAGE_SIZE);
        paramMap.put("appId", appId);
        
        int total = operLogManager.getByappIdForCount(paramMap);
        List<OperLog> operLogs = operLogManager.getByAppId(paramMap);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("appList", operLogs);
        resultMap.put("total", total);
        resultMap.put("pageSize", Constants.Common.PAGE_SIZE);
        resultMap.put("pageNo", pageNo);
        return Result.get(resultMap, Constants.Common.SUCCESS);
    }
}
